package customer.zspt.cn.customer.Widget.chat;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lidroid.xutils.BitmapUtils;

import customer.zspt.cn.customer.R;
import customer.zspt.cn.customer.components.chat.ChatOtherThingContent.ChatArticleContent;
import customer.zspt.cn.customer.utils.TimestampToBj;

/**
 * Created by Administrator on 2018/7/24 0024.
 */

public class ChatArticleLeftMsgItem extends LinearLayout implements View.OnClickListener{
    private final ImageView Article_ig;
    private final TextView ArticleTitle;
    private final ImageView header_portrait;
    private final TextView Article_outline;
    private final TextView ArticleUrl;
    private final LinearLayout JumpContent;
    private final TextView msg_time;
    private BitmapUtils utils;
    public ChatArticleLeftMsgItem(Context context) {
        this(context,null);
    }
    public ChatArticleLeftMsgItem(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,0);
    }
    public ChatArticleLeftMsgItem(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        utils = new BitmapUtils(context);
        View.inflate(context, R.layout.chat_msg_article_left_item,this);
        Article_ig = (ImageView) findViewById(R.id.Article_ig);
        ArticleTitle = (TextView) findViewById(R.id.ArticleTitle);
        header_portrait = (ImageView) findViewById(R.id.header_portrait);
        Article_outline = (TextView) findViewById(R.id.Article_outline);
        ArticleUrl = (TextView) findViewById(R.id.articleUrl);
        JumpContent = (LinearLayout) findViewById(R.id.JumpContent);
        msg_time = (TextView)findViewById(R.id.msg_time);
        JumpContent.setOnClickListener(this);
    }
    //头像
    public void setHeader_portrait(String imageUrl)
    {
        utils.display(header_portrait,imageUrl);
    }
    public void setTime(long time,long ChatTime)
    {
        if (time - ChatTime > 3 * 60 * 1000) {
            msg_time.setText(TimestampToBj.getBeijingTime(time));
        } else {
            msg_time.setVisibility(View.GONE);
        }
    }
    //文章图
    public void setArticle_ig(String article_ig){
        utils.display(Article_ig,article_ig);
    }
    //文章梗概
    public void setArticle_outline(String article_outline){
        Article_outline.setText(article_outline);
    }
    //文章标题
    public void setArticleTitle(String articleTitle){
        ArticleTitle.setText(articleTitle);
    }
    //文章网址
    public void setArticleUrl(String articleUrl)
    {
        ArticleUrl.setText(articleUrl);
    }
    @Override
    public void onClick(View v) {
        String url = ArticleUrl.getText().toString();
        Intent intent = new Intent(getContext(), ChatArticleContent.class);
        intent.putExtra("article_contentUrl",url);
        getContext().startActivity(intent);
    }
}
